<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}" @reset="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="平台名称" name="name">
            <t-input
              v-model="queryParams.name"
              clearable
              placeholder="请输入平台名称"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="平台类别" name="platformCategory">
            <t-select  style="width: 240px" clearable v-model="queryParams.platformCategory"
                       :options="dict.type.platform_category">
            </t-select>
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="base" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-table
      rowKey="index"
      size="small"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
      :sort="sort"
      :hideSortTips="true"
      @sort-change="sortChange"
    >
      <template #name="{ row }">
        <t-link @click="dialog.objId=row.id;dialog.header=row.name;dialog.open_project_detail=true" hover="color" theme="primary">{{row.name}}</t-link>
      </template>
      <template #platformCategory="{ row }">
        {{ row.platformCategory | filterByDict(dict.type.platform_category) }}
      </template>
      <template #patentCount="{ row }">
        <t-link @click="perInfo(1,row)" hover="color" theme="primary">{{row.patentCount}}</t-link>
      </template>
      <template #thesisCount="{ row }">
        <t-link @click="perInfo(2,row)" hover="color" theme="primary">{{row.thesisCount}}</t-link>
      </template>
      <template #awardsCount="{ row }">
        <t-link @click="perInfo(3,row)" hover="color" theme="primary">{{row.awardsCount}}</t-link>
      </template>
      <template #treatiseCount="{ row }">
        <t-link @click="perInfo(4,row)" hover="color" theme="primary">{{row.treatiseCount}}</t-link>
      </template>
      <template #softwareCopyrightCount="{ row }">
        <t-link @click="perInfo(5,row)" hover="color" theme="primary">{{row.softwareCopyrightCount}}</t-link>
      </template>
      <template #op="{ row }">
        <t-dropdown   trigger="click">
          <t-button size="small" variant="text" class="t-button-link">
            <t-icon name="chevron-right-double" slot="icon"/>
            录入
          </t-button>
          <t-dropdown-menu  slot="dropdown">
            <t-dropdown-item v-for="(item,index) in options" :key="index"  @click="clickHandler(item.value)" class="no-margin-padding-dropdown-item" :value="2"> <t-button  size="small" variant="text" class="t-button-link">
                            {{item.content}}
                          </t-button></t-dropdown-item>
           <t-dropdown-item  @click="dialog.userId=row.id;dialog.userName=row.userName;dialog.open_reset_user_password=true" class="no-margin-padding-dropdown-item" :value="1"><t-button  size="small" variant="text" class="t-button-link">
            
           </t-button></t-dropdown-item>
           <t-dropdown-item  @click="handlerUserRole(row.id)" class="no-margin-padding-dropdown-item" :value="2"> <t-button  size="small" variant="text" class="t-button-link">
             分配角色
           </t-button></t-dropdown-item>
          </t-dropdown-menu>
        </t-dropdown>
        <t-button size="small" @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_project_detail=true" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
        <t-button
          theme="danger"
          @click="deleteProject(row)"
          size="small"
          variant="text" class="t-button-link">
          <t-icon name="delete" slot="icon"/>
          删除
        </t-button>
      </template>
    </t-table>
    <platform-detail-dialog :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_project_detail" v-if="dialog.open_project_detail"></platform-detail-dialog>
    <havaProjectInfo @closeBzhDialog="closeBzhDialog" v-if="nowInfo==1"  :dialogInfo="detailDialog"></havaProjectInfo>
    <peopleInfo @closeBzhDialog="closeBzhDialog" v-if="nowInfo==2"  :dialogInfo="detailDialog"></peopleInfo>
    <fundingInfo @closeBzhDialog="closeBzhDialog" v-if="nowInfo==3" :dialogInfo="detailDialog"></fundingInfo>
    <equipmentInfo  @closeBzhDialog="closeBzhDialog" v-if="nowInfo==4"  :dialogInfo="detailDialog"></equipmentInfo>
  </div>
</template>

<script>
import platformDetailDialog from "@/pages/kjpt/platform/components/platform-detail-dialog.vue";
import equipmentInfo from "@/pages/kjpt/components/equipment-info.vue";
import fundingInfo from "@/pages/kjpt/components/funding-info.vue";
import havaProjectInfo from "@/pages/kjpt/components/havaProject-info.vue";
import peopleInfo from "@/pages/kjpt/components/people-info.vue";

export default {
  name: "list",
  dicts: ["platform_category"],
  components: {
    platformDetailDialog,
    equipmentInfo,
    fundingInfo,
    havaProjectInfo,
    peopleInfo
  },
  data() {
    return {
      detailDialog:{
        id:"",
        header:"",
        visible: false,
      },
      nowInfo:0,
      data2:[],
      sort:[],
      dialog: {
        open_project_detail: false,
        header: "",
        objId: 0,
        open_approve_list: false,
        open_project_file: false
      },
      dictTypes: {},
      projectCategoryOptions: [],
      columns:[
        {
          colKey: "name",
          title: "平台名称",
          align: "center",
          width: 220

        },
        {
          colKey: "platformCategory",
          title: "平台类别",
          align: "center",
          width: 160,
        },
        {
          colKey: "buildDate",
          title: "立项时间",
          align: "center",
          sorter: true,
          width: 180
        },
        {
          colKey: "thesisCount",
          title: "论文个数",
          align: "center",
          width: 100,
          fixed: 'right'
        },
        {
          colKey: "patentCount",
          title: "专利个数",
          align: "center",
          width: 100,
          fixed: 'right'
        },
        {
          colKey: "treatiseCount",
          title: "专著个数",
          align: "center",
          width: 100,
          fixed: 'right'
        },
        {
          colKey: "softwareCopyrightCount",
          title: "软著个数",
          align: "center",
          width: 100,
          fixed: 'right'
        },
        {
          colKey: "awardsCount",
          title: "奖励个数",
          align: "center",
          width: 100,
          fixed: 'right'
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120,
          fixed: 'right'
        },
      ],
      data: [],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name:"",
        platformCategory:""
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  async created() {
    this.getList();
  },
  methods: {
    closeBzhDialog(data){
      this.nowInfo = 0
      // this.detailDialog.visible = data
    },
    perInfo(index,row){
      if(index==1) { // 专利
        this.$router.push({
          path:"/cgzh/patent/patent-my",
          query:{
            serviceCode:"kjpt",
            // name:row.name
          }
        })
      }
      if(index==2){ // 论文
        this.$router.push({
          path:"/cgzh/thesis/thesis-my",
          query:{
            serviceCode:"kjpt",
            // name:row.name
          }
        })
      }
      if(index==3) { // 奖励
        this.$router.push({
          path:"/cgzh/awards/awards-my",
          query:{
            serviceCode:"kjpt",
            // name:row.name
          }
        })
      }
      if(index==4) { // 专著
        this.$router.push({
          path:"/cgzh/treatise/treatise-my",
          query:{
            serviceCode:"kjpt",
            // name:row.name
          }
        })
      }
      if(index==5) { // 软著
        this.$router.push({
          path:"/cgzh/copyright/copyright-my",
          query:{
            serviceCode:"kjpt",
            // name:row.name
          }
        })
      }
    },
    sortChange(sort){
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if(sort instanceof Array){
        orderByColumn = sort.map(val=>val.sortBy)
        isAsc = sort.map(val=>val.descending?`desc`:`asc`)
      }else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending?`desc`:`asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    getList() {
      this.dataLoading = true;
      this.queryParams.pageNum = this.pagination.current || 1;
      this.$api.kjpt.ptInfo.list(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    apply() {
      this.$router.push(`/kjpt/other/pm/platform-apply/${Date.parse(new Date())}`);
    },
    deleteProject(row) {
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除项目名称为"${row.projectName}"的数据项？`,
        theme: "warning",
        onConfirm: ({e}) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.kjxm.project.del(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        }
      });
    },
  }
}
</script>

<style scoped>

</style>
